package com.bilibili.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bilibili.entity.CommonResult;
import com.bilibili.entity.Page;
import com.bilibili.entity.User;
import com.bilibili.service.UserService;
import com.bilibili.service.impl.UserServiceImpl;

@SuppressWarnings("serial")//抑制serialVersionUID字段警告
@WebServlet("/AttentionToMe")
public class QueryAllAttentionToMeServlet extends HttpServlet{

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("application/json; charset=utf-8");
		int user_id = ((User) request.getSession().getAttribute("loginUser")).getUserId();
		String nickName = request.getParameter("nickName");
		int pageNum = 1,pageSize = 9;
		if(request.getParameter("pageNum") != null){
			pageNum = Integer.parseInt(request.getParameter("pageNum"));
		}
		
		if(request.getParameter("pageSize") != null){
			pageSize = Integer.parseInt(request.getParameter("pageSize"));
		}

		User user = new User();
		user.setUserId(user_id);
		user.setNickname(nickName);
		UserService userService = new UserServiceImpl();
		Page<User> userPage = userService.queryAllAttentionToMe(user,pageNum,pageSize);
		if(userPage.getData().size() != 0) {
			CommonResult cr = new CommonResult();
			cr.setCode(200);
			cr.setData(userPage);
			response.getWriter().write(cr.toJSONString());
		}else {
			CommonResult cr = new CommonResult();
			cr.setCode(409);
			response.getWriter().write(cr.toJSONString());
		}
	}
}
